﻿@model WebApp.Models.PICKDETAIL
@{  ViewBag.Title = "拣货明细 | Create";}
<!-- MAIN CONTENT -->
<div id="content">
    <!-- quick navigation bar -->
    <div class="row">
        <div class="col-xs-12 col-sm-7 col-md-7 col-lg-4">
            <h1 class="page-title txt-color-blueDark">
                <i class="fa fa-table fa-fw "></i>
                出库作业
                <span>
                    >
                    拣货明细
                </span>
            </h1>
        </div>
        <div class="col-xs-12 col-sm-5 col-md-5 col-lg-8">
        </div>
    </div>
     <!-- widget grid -->
    <section id="widget-grid" class="">
        <!-- row -->
        <div class="row">
    <!-- NEW WIDGET START -->
    <article class="col-sm-12 col-md-12 col-lg-12">
        <!-- Widget ID (each widget will need unique ID)-->
        <div class="jarviswidget" id="wid-id-1" data-widget-editbutton="false" data-widget-deletebutton="false">
            <!-- widget options:
            usage: <div class="jarviswidget" id="wid-id-0" data-widget-editbutton="false">
            data-widget-colorbutton="false"
            data-widget-editbutton="false"
            data-widget-togglebutton="false"
            data-widget-deletebutton="false"
            data-widget-fullscreenbutton="false"
            data-widget-custombutton="false"
            data-widget-collapsed="true"
            data-widget-sortable="false"
            -->
            <header>
                <span class="widget-icon"> <i class="fa fa-edit"></i> </span>
                <h2> 拣货明细 </h2>
            </header>
            <!-- widget div-->
            <div>
                <!-- widget edit box -->
                <div class="jarviswidget-editbox">
                    <!-- This area used as dropdown edit box -->
                </div>
                <!-- end widget edit box -->
                <!-- widget content -->
                <div class="widget-body">
                    <div class="widget-body-toolbar">
                        <div class="row">
                            <div class="col-sm-8  ">
                                <div class="btn-group">
                                    <a href="javascript:saveitem()" class="btn btn-sm btn-primary"> <i class="fa fa-floppy-o"></i> @Html.L("Save") </a>
                                </div>
                                <div class="btn-group" style="display:none">
                                    <a href="javascript:todo()" class="btn btn-sm btn-primary"> <i class="fa fa-print"></i> ToDo </a>
                                </div>
                            </div>
                            <div class="col-sm-4 text-align-right">
                                <div class="btn-group">
                                    <a href="/PICKDETAILs/Index" class="btn btn-sm btn-success"> <i class="fa fa-chevron-left"></i> @Html.L("GoBack") </a>
                                </div>
                            </div>
                        </div>

                    </div>
                    <div class="body-content">
                         @Html.Partial("EditForm")
                    </div>		 
                 </div>
                 <!-- end widget content -->
                 </div>
            <!-- end widget div -->
        </div>
        <!-- end widget -->
    </article>
    <!-- WIDGET END -->
</div>
 
</section>
</div>
<!-- END MAIN CONTENT -->
@section Scripts {
<script type="text/javascript">
	    var pickdetailid=@Model.ID;
        var $editform = $('#pickdetail_form');
        //保存
        function saveitem() {
			  if ($editform.valid()) {
                 var pickdetail = $editform.serializeJSON();
                 var token = $('input[name="__RequestVerificationToken"]', $editform).val();
                 $.ajax({
                    type: "POST",
                    url: "/PICKDETAILs/CreateAsync",
                    data: {
                        __RequestVerificationToken: token,
                        pickdetail:pickdetail
                    },
                    dataType: 'json',
                    contentType: 'application/x-www-form-urlencoded; charset=utf-8',
                })
                .done(response => {
                    if (response.success) {
                        toastr.success('保存成功'); 
                        window.location.href = "/PICKDETAILs/Index";
                    } else {
                        $.messager.alert("错误", response.err, "error");
                    }
                    })
                .fail((jqXHR, textStatus, errorThrown) => {
                        $.messager.alert("异常",  errorThrowne ,"error");
                    });
                  
             }						
        }
        //ToDo
        function todo() {
        }
      

     /********************************
     *
     * pageSetUp() is needed whenever you load a page.
     * It initializes and checks for all basic elements of the page
     * and makes rendering easier.
     *
     */
     //pageSetUp();
     /********************************
     *
     * pagefunction() $editform 校验规则
     *
     */
     var pagefunction = function () {
            var errorClass = 'has-error';
            var successClass = 'has-success';
            var errorElement = 'em';
            $editform.validate({
                 errorElement: errorElement,
      errorPlacement: function (error, element) {
         // Add the `help-block` class to the error element
         error.addClass("help-block no-margin");
         if (element.prop("type") === "checkbox") {
          error.insertAfter(element.parent("label"));
         } else if (element.prop("type") === "date" || element.prop("type") === "datetime" ) {
          error.insertAfter(element.parent(".input-group"));
         } else {
          error.insertAfter(element);
         }
       },
       highlight: function (element, errorClass, validClass) {
        $(element).parents("div").addClass("has-error").removeClass("has-success");
       },
       unhighlight: function (element, errorClass, validClass) {
        $(element).parents("div").addClass("has-success").removeClass("has-error");
       },
                // Rules for form validation
                rules: {
                    PICKDETAILKEY:{
                            required:true,
                            rangelength: [0, 20],
                    },
                    WHSEID:{
                            required:true,
                            rangelength: [0, 20],
                    },
                    ORDERKEY:{
                            required:true,
                            rangelength: [0, 20],
                    },
                    EXTERNRECEIPTKEY:{
                            required:false,
                            rangelength: [0, 30],
                    },
                    STORERKEY:{
                            required:true,
                            rangelength: [0, 50],
                    },
                    STATUS:{
                            required:false,
                            rangelength: [0, 3],
                    },
                    SKU:{
                            required:true,
                            rangelength: [0, 30],
                    },
                    SKUNAME:{
                            required:false,
                            rangelength: [0, 80],
                    },
                    QTY:{
                            required:true,
                            number: true,
                    },
                    UMO:{
                            required:true,
                            rangelength: [0, 10],
                    },
                    CASECNT:{
                            required:true,
                            number: true,
                    },
                    LOC:{
                            required:false,
                            rangelength: [0, 20],
                    },
                    LOT:{
                            required:false,
                            rangelength: [0, 20],
                    },
                    LPN:{
                            required:false,
                            rangelength: [0, 20],
                    },
                    SUPPLIERCODE:{
                            required:false,
                            rangelength: [0, 20],
                    },
                    SUPPLIERNAME:{
                            required:false,
                            rangelength: [0, 80],
                    },
                    RECEIPTKEY:{
                            required:true,
                            rangelength: [0, 20],
                    },
                    POKEY:{
                            required:false,
                            rangelength: [0, 30],
                    },
                    RECEIPTDATE:{
                            required:true,
                            date: true,
                    },
                    PALLET:{
                            required:true,
                            number: true,
                    },
                    PACKKEY:{
                            required:false,
                            rangelength: [0, 10],
                    },
                    GROSSWGT:{
                            required:true,
                            number: true,
                    },
                    NETWGT:{
                            required:true,
                            number: true,
                    },
                    CUBE:{
                            required:true,
                            number: true,
                    },
                    LOTTABLE1:{
                            required:false,
                            rangelength: [0, 50],
                    },
                    LOTTABLE2:{
                            required:false,
                            rangelength: [0, 50],
                    },
                    LOTTABLE3:{
                            required:false,
                            rangelength: [0, 50],
                    },
                    LOTTABLE4:{
                            required:false,
                            rangelength: [0, 50],
                    },
                    LOTTABLE5:{
                            required:false,
                            rangelength: [0, 50],
                    },
                    LOTTABLE6:{
                            required:false,
                            number: true,
                    },
                    LOTTABLE7:{
                            required:false,
                            number: true,
                    },
                    LOTTABLE8:{
                            required:false,
                            date: true,
                    },
                    ORDERID:{
                            required:true,
                            digits: true,
                    },
                },
                // Messages for form validation
                messages:{
                
                },
                submitHandler:  (form) => {
                      //调用保存方法
                      saveitem();
                      return false;
                    //$(form).ajaxSubmit({
                    //    success: function () {
                    //        console.log('ajaxSubmit success');
                    //   }
                    //});
                }
            });
        }
        pagefunction();
</script>

 <!-- 初始化from -->
 <script type="text/javascript">
    
    function initFormData(id) {
            //$('#pickdetail_form').form('load', data);
            
    }


   var pickdetailid=@Model.ID;
    $(function(){
        initFormData(pickdetailid);
    });
 </script>

}
